package com.elvin.zoe.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class FileUtil {

    public static String readFile(File file) throws IOException {
        StringBuffer stringBuffer = new StringBuffer();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
        while (true) {
            String str = bufferedReader.readLine();
            if (str == null)
                break;
            stringBuffer.append(str.trim() + "\n");
        }
        return stringBuffer.toString();
    }

    public static void writeFile(File file, String text) throws IOException{
        OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
        BufferedWriter writer = new BufferedWriter(write);
        writer.write(text);
        writer.flush();
        writer.close();
    }

}
